package com.youhome.api.controller;

import com.youhome.api.dto.*;
import com.youhome.common.exception.CustomException;
import com.youhome.service.service.ZilLowByCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2019/04/15.
 */
@RestController
@Api(tags = "分析")
@RequestMapping("/homes/")
public class AnalysisCityController {
    @Autowired
    private ZilLowByCityService zilLowByCityService;

    @ApiOperation(value = "时间序列统计分析", notes = "时间序列统计分析", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "county", value = "郡县", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/timeseries-city/{type}/{city}/{state}/{county}")
    public Object timeSeries(@PathVariable Integer type, @PathVariable String city, @PathVariable String state, @PathVariable String county) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.getTimeSeriesByCity(type, city, state, county,0));
    }

    @ApiOperation(value = "时间序列统计分析", notes = "时间序列统计分析", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/timeseries-city/{type}/{city}/{state}")
    public Object timeSeries(@PathVariable Integer type, @PathVariable String city, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.getTimeSeriesByCity(type, city, state,0));
    }

    /*
    @ApiOperation(value = "时间序列统计分析", notes = "时间序列统计分析", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "zipcode", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/timeseries-city/{type}/{zip}")
    public Object timeSeries(@PathVariable Integer type, @PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.getTimeSeriesByCity(type, zip,0));
    }
    */

    @ApiOperation(value = "买卖指数", notes = "买卖指数", response = BuyerSellerResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/buyer-seller-city/{city}/{state}")
    public Object buyerSeller(@PathVariable String city, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_Buyer_Seller_Index_City(city, state));
    }

    /*
    @ApiOperation(value = "买卖指数", notes = "买卖指数", response = BuyerSellerResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "zip", value = "zipcode", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/buyer-seller-city/{zip}")
    public Object buyerSeller(@PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_Buyer_Seller_Index_City(zip));
    }
    */

    @ApiOperation(value = "房屋价格指数", notes = "房屋价格指数", response = ZHVIResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/price-index-city/{city}/{state}")
    public Object priceIndex(@PathVariable String city, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_City_Zhvi_Summary_AllHomes(city, state));
    }

    @ApiOperation(value = "房屋价格指数", notes = "房屋价格指数", response = ZHVIResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "county", value = "郡县", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/price-index-city/{city}/{state}/{county}")
    public Object priceIndex(@PathVariable String city, @PathVariable String state, @PathVariable String county) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_City_Zhvi_Summary_AllHomes(city, state, county));
    }

    /*
    @ApiOperation(value = "房屋价格指数", notes = "房屋价格指数", response = ZHVIResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "zip", value = "zipcode", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/price-index-city/{zip}")
    public Object priceIndex(@PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_City_Zhvi_Summary_AllHomes(zip));
    }

    */

    @ApiOperation(value = "租房指数", notes = "租房指数", response = ZriResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/rent-index-city/{type}/{city}/{state}")
    public Object zri(@PathVariable Integer type, @PathVariable String city, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_City_Zri_AllHomes_Summary(type, city, state));
    }

    @ApiOperation(value = "租房指数", notes = "租房指数", response = ZriResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "county", value = "郡县", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/rent-index-city/{type}/{city}/{state}/{county}")
    public Object zri(@PathVariable Integer type, @PathVariable String city, @PathVariable String state, @PathVariable String county) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_City_Zri_AllHomes_Summary(type, city, state, county));
    }

    /*
    @ApiOperation(value = "租房指数", notes = "租房指数", response = ZriResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "zipcode", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/rent-index-city/{type}/{zip}")
    public Object zri(@PathVariable Integer type, @PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_City_Zri_AllHomes_Summary(type, zip));
    }

    */

    @ApiOperation(value = "市场健康指数", notes = "市场健康指数", response = MarketHealthResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "city", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/market-health-city/{city}/{state}")
    public Object marketHealth(@PathVariable String city, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_Market_Health_Index_City(city, state));
    }

    /*
    @ApiOperation(value = "市场健康指数", notes = "市场健康指数", response = MarketHealthResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "zip", value = "zipcode", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/market-health-city/{zip}")
    public Object marketHealth(@PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByCityService.get_Market_Health_Index_City(zip));
    }

    */
}
